
import Feature from 'ol/Feature';
import { Polygon } from 'ol/geom'
import { mapManager } from "../MapManager";
import http from '@/api/js/http'
import { Style, Fill, Stroke } from 'ol/style';

/**
 *  地块信息
 */
class Field     {

    static FIELD__INDEX = 0;

    /**
     * 构造函数
     * @param {Feature} f 
     */
    constructor() {
       

      
    }
 

    


    /**
     * 初始化数据
     */
    static initData() {

        http.get("/reg_area/list").then(
            (resp)=>{
                var list = resp.data;
                
                //@ts-ignore
                list.forEach((item)=>{
                    var area = item.area;
                    var coordinateGroup = null;
                    try {
                        
                         

                        coordinateGroup = JSON.parse(area);

                       // console.log(coordinateGroup)

                        var polygon = new Feature({
                            geometry: new Polygon([coordinateGroup]),
        
                        });
        
                        //var fieldWrapper = new Field(polygon, field);

                        

                        mapManager.getLayers().fieldSource.addFeature(polygon); 


                        var style = new Style({
                            stroke: new Stroke({
                                color: 'red',
                                width: 3, //@ts-ignore
                                lineDash:0
                            }),
                            fill: new Fill({
                                color: "rgba(255,255,255,0.5 )"
                            })
                        });

                        polygon.setStyle(style);

                    } catch (e) { 
                        console.log(e)
                        coordinateGroup = null; }
                    

    
                    
                });

                
             
                
            }
        );

        
    }
    

 
  
}

export default Field;